package net.homelinux.chaoswg.io.renga.krypto.operations.type;

import java.math.BigInteger;
import java.util.List;

import net.homelinux.chaoswg.io.higherorderfunctions.AbstractBinaryFunction;
import net.homelinux.chaoswg.io.higherorderfunctions.BinaryFunction;
import net.homelinux.chaoswg.io.renga.krypto.datatypes.numerical.UnsignedNBit;

public class PiI extends AbstractBinaryFunction<Object, java.util.List, net.homelinux.chaoswg.io.renga.krypto.datatypes.numerical.UnsignedNBit> implements BinaryFunction<Object, java.util.List, net.homelinux.chaoswg.io.renga.krypto.datatypes.numerical.UnsignedNBit> {
    public Object apply (final List l, final UnsignedNBit i) {
        final int listSize = l.size();
        final BigInteger iVal = i.getValue();
        final BigInteger listSizeBig = new BigInteger (new Integer (listSize).toString());
        
        if (iVal.compareTo(listSizeBig) <= 0 ) {
            final int index = new Integer (iVal.toString());
            return l.get(index);
        }
        throw new IllegalArgumentException ("Index to large");
    }
}
